package com.yc.cloud.basic.controller;

import cn.hutool.core.util.StrUtil;
import com.yc.cloud.basic.dto.BaseQueryParam;

/**
 * 基础控制器,增加了默认分页参数设置
 */
public abstract class BaseController {


    protected void setDefaultValues(BaseQueryParam queryParam) {
        if (queryParam.getPageNum() == null) {
            queryParam.setPageNum(BaseQueryParam.DEFAULT_NUM); // 设置默认值
        }

        if (queryParam.getPageSize() == null) {
            queryParam.setPageSize(BaseQueryParam.DEFAULT_SIZE); // 设置默认值
        }

        if (queryParam.getPage() == null) {
            queryParam.setPage(true); // 设置默认值
        }
        if (StrUtil.isEmpty(queryParam.getSortBy())) {
            queryParam.setSortBy(BaseQueryParam.DEFAULT_SORT_BY); // 设置默认值
        }
        if (StrUtil.isEmpty(queryParam.getOrder())) {
            queryParam.setOrder(BaseQueryParam.ORDER_DESC); // 设置默认值
        }
    }
}
